import { ratioSticsData } from '@/services/datastatistics';

export default {
    namespace: 'answerRatioStatis',

    state: {
        hitAllCount: '',
        hitUserCount: '',
        hitSysCount: '',
        hitUnknownCount: '',
        resolvedData: [],
        resolvedInUserData: [],
        channelData: [],
        hitAllData: [],
        chatCountList: [],
        unknownCountList: [],
        userCountList: [],
        systemCountList: [],
    },
    effects: {
        *fetch({ payload, callback }, { call, put }) {
            const response = yield call(ratioSticsData, payload);
            if (response) {
                if (callback && typeof callback === 'function') {
                    callback(response);
                }
                yield put({
                    type: 'save',
                    payload: response,
                });
            }
        },
    },

    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload,
            };
        },
        clear() {
            return {
                hitAllCount: '',
                hitUserCount: '',
                hitSysCount: '',
                hitUnknownCount: '',
                resolvedData: [],
                resolvedInUserData: [],
                channelData: [],
                hitAllData: [],
                chatCountList: [],
                unknownCountList: [],
                userCountList: [],
                systemCountList: [],
            };
        },
    },
};
